import Vue from "vue";
import VueRouter from "vue-router";
import axios from "axios";

import Login from "../views/Login";

//admin组件
import Admin from "../views/Admin";
import SiteData from "../views/main/SiteData";

import Module from "../views/main/Module";
import ModuleSub from "../views/main/module/ModuleSub";
import AddModule from "../views/main/module/AddModule";
import AddModuleSub from "../views/main/module/AddModuleSub";
import Article from "../views/main/module/Article";
import AddArticle from "../views/main/module/AddArticle";
import Product from "../views/main/module/Product";
import AddProduct from "../views/main/module/AddProduct";
import Category from "../views/main/module/Category";
import ModuleComType from "../views/main/module/ModuleComType";
import AddModuleComType from "../views/main/module/AddModuleComType";
import ModuleMaterial from "../views/main/module/ModuleMaterial";
import ModuleMaterialSub from "../views/main/module/ModuleMaterialSub";
import AddModuleMaterial from "../views/main/module/AddModuleMaterial";
import AddModuleMaterialSub from "../views/main/module/AddModuleMaterialSub";
//system组件
import Employee from "../views/main/module/Employee";
import AddEmployee from "../views/main/module/AddEmployee";
import Resources from "../views/main/module/Resources";
import Roles from "../views/main/module/Roles";
import Member from "../views/main/module/Member";
import AddMember from "../views/main/module/AddMember";
import SiteSet from "../views/main/module/SiteSet";
import SiteSingle from "../views/main/module/SiteSingle";
import SiteLink from "../views/main/module/SiteLink";
import SiteThirdCodeSet from "../views/main/module/SiteThirdCodeSet";
//公共组件
import PageHelper from "../components/PageHelper";
import "element-ui/lib/theme-chalk/index.css";
//文件组件
import File from "../views/main/module/File";
import FileMaterials from "../views/main/module/FileMaterials";
//短信管理
import ShortMessage from "../views/main/module/ShortMessage";
import AddShortMessage from "../views/main/module/AddShortMessage";
//留言管理
import GuestBook from "../views/main/module/GuestBook";
import AddGuestBook from "../views/main/module/AddGuestBook";
//数据组件：店铺
import Store from "../views/main/module/Store";
import AddStore from "../views/main/module/AddStore";

Vue.use(VueRouter);

//配置vue全局变量：任意组件--》this.$ajax可使用axios
Vue.prototype.$axios=axios;

const routes = [
    {
        path: '/',
        name: 'login',
        //component:Login,
        /*
        这里可使用redirect执行跳转
        使用redirect区别，输入任意路径，路径名http://localhost:8080/asdasdasd都会更改为http://localhost:8080/login
         */
        redirect: '/login'
    }, {
        name: '/login',
        path: '/login',
        component: Login
    }, {
        path: '/',
        name: 'admin',
        component: Admin,
        meta:{
            loginRequired:true
        },
        children: [
            {   //子路由不以斜杠/开头路径
                path: 'system/site/data',
                name:'system/site/data',
                component: SiteData,
            },
            {   //子路由不以斜杠/开头路径
                path: 'business/store/set',
                name:'business/store/set',
                component: Store,
            },
            {
                path: 'business/store/add',
                name:'business/store/add',
                component: AddStore,
            },
            {
                path: 'system/manager/employee',
                name: 'system/manager/employee',
                component: Employee,
            },
            {
                path:'business/employee/add',
                name: 'business/employee/add',
                component: AddEmployee,
            },
            {
                path: 'system/manager/resources',
                name: 'system/manager/resources',
                component: Resources,
            },
            {
                path: 'system/manager/roles',
                name: 'system/manager/roles',
                component: Roles,
            },
            {
                path: 'system/manager/member',
                name: 'system/manager/member',
                component: Member,
            },
            {
                path: 'system/manager/member/add',
                name: 'system/manager/member/add',
                component: AddMember,
            },
            {
                path: 'system/site/set',
                name: 'system/site/set',
                component: SiteSet,
            },
            {
                path: 'system/site/single',
                name: 'system/site/single',
                component: SiteSingle,
            },
            {
                path: 'system/site/link/set',
                name: 'system/site/link/set',
                component: SiteLink,
            },
            {
                path: 'system/site/thirdcode',
                name: 'system/site/thirdcode',
                component: SiteThirdCodeSet,
            },
            {
                path: 'business/category',
                name: 'business/category',
                component: Category,
            },

            {
                path: 'business/module/set',
                name:'business/module/set',
                component: Module,
            },
            {
                path: 'business/module/add',
                name: 'business/module/add',
                component: AddModule,
            },
            {
                path: 'business/module/sub',
                name: 'business/module/sub',
                component: ModuleSub,
            },
            {
                path: 'business/module/sub/add',
                name: 'business/module/sub/add',
                component: AddModuleSub,
            },
            {
                path: 'business/module/com',
                name: 'business/module/com',
                component: ModuleComType,
            },
            {
                path: 'business/module/com/add',
                name: 'business/module/com/add',
                component: AddModuleComType,
            },
            {
                path: 'business/module/material',
                name: 'business/module/material',
                component: ModuleMaterial,
            },
            {
                path: 'business/module/material/add',
                name: 'business/module/material/add',
                component: AddModuleMaterial,
            },
            {
                path: 'business/material/sub',
                name: 'business/material/sub',
                component: ModuleMaterialSub,
            },
            {
                path: 'business/material/sub/add',
                name: 'business/material/sub/add',
                component: AddModuleMaterialSub,
            },
            {
                path: 'business/article/set',
                name: 'business/article/set',
                component: Article,
            },
            {
                path: 'business/article/add',
                name: 'business/article/add',
                component: AddArticle,
            },
            {
                path: 'business/product/set',
                name: 'business/product/set',
                component: Product,
            },
            {
                path: 'business/product/add',
                name: 'business/product/add',
                component: AddProduct,
            },
            {
                path: 'source/manager/file',
                name: 'source/manager/file',
                component: File,
            },
            {
                path: 'source/shortMessage/set',
                name: 'source/shortMessage/set',
                component: ShortMessage,
            },
            {
                path: 'source/shortMessage/add',
                name: 'source/shortMessage/add',
                component: AddShortMessage,
            },
            {
                path: 'source/guestBook/set',
                name: 'source/guestBook/set',
                component: GuestBook,
            },
            {
                path: 'source/guestBook/add',
                name: 'source/guestBook/add',
                component: AddGuestBook,
            },
            {
                path: 'source/file/materials',
                name: 'source/file/materials',
                component: FileMaterials,
            },
        ]
    },
    {
        path: '/pageHelper',
        name: 'PageHelper',
        component: PageHelper
    }
]

const router = new VueRouter({
    /*
    后端数据请求模式：history
    前端无请求模式#(难以请求后端数据)：hash
     */
    mode: 'history',
    //vue-router内置变量路径，指向public目录
    base: process.env.BASE_URL,
    routes
})
//避免同一导航，重复点击报错

//抛出路由
export default router;